<template>
  <div class="container">
    <el-row type="flex" justify="space-between">
      <div style="width:8%;display:flex;justify-content: left;">
        <el-button @click="exportExcel" type="success" icon="el-icon-download">导出</el-button>
      </div>
      <div style="width:72%">
        <el-select v-model="form.selectNetCode" placeholder="请选择台网" style="margin-left: 10px;width: 15%;">
          <el-option v-for="item in netCodeOptions" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
        <el-select v-model="form.selectChanNum" placeholder="请选择位置号" style="margin-left: 10px;width: 15%;">
          <el-option v-for="item in chanNumOptions" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
        <el-select v-model="form.selectChanCode" placeholder="请选择通道码" style="margin-left: 10px;width: 15%;">
          <el-option v-for="item in chanCodeOptions" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
        <el-input v-model="form.intThreshold" placeholder="请输入波形异常次数阈值" style="margin-left: 10px;width: 15%;" type="number"></el-input>
        <el-date-picker
          v-model="form.date"
          style="margin-left: 10px;width: 35%;"
          type="datetimerange"
          format="yyyy-MM-dd HH:mm:ss"
          value-format="yyyy-MM-dd HH:mm:ss"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </div>
      <div>
        <el-button style="margin-left: 10px" @click="queryData" type="primary" icon="el-icon-search">查询</el-button>
        <el-button style="margin-left: 10px" @click="clearFn" type="danger" icon="el-icon-delete">清除</el-button>
      </div>
    </el-row>

    <el-table :data="tableData" style="width: 100%;margin-top:15px;" border :cell-style="cellStyle" :row-style="{height:'40px'}" >
      <el-table-column prop="alarmLevel" label="alarmLevel" align="center">
      </el-table-column>
      <el-table-column prop="alarmName" label="alarmName" align="center" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="alarmStatus" label="alarmStatus" align="center">
      </el-table-column>
      <el-table-column prop="alarmValue" label="alarmValue" align="center" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="alramType" label="alramType" align="center" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="codeFull" label="codeFull" align="center" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="id" label="id" align="center" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="lastUpdateTime" label="lastUpdateTime" align="center" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="meaning" label="meaning" align="center" width="350" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="netCode" label="netCode" align="center">
      </el-table-column>
      <el-table-column prop="rtTime" label="rtTime" align="center" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="staCode" label="staCode" align="center">
      </el-table-column>
      <el-table-column prop="staType" label="staType" align="center">
      </el-table-column>
    </el-table>
    <div class="page">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pageInfo.pageNum" :page-sizes="[5, 10, 15, 20]" :page-size="pageInfo.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total">
      </el-pagination>
    </div>

  </div>
</template>

<script>
import { getAllChanCode, getAllChanNum, getAllNetCode, getNetCode } from '@/api'
export default {
  name: 'Home',
  data () {
    return {
      tableData: [],
      pageInfo: {
        pageNum: 1,
        pageSize: 10,
        startDate: '',
        endDate: ''
      },
      form: {
        selectChanCode: '',
        selectChanNum: '',
        selectNetCode: '',
        intThreshold: 0, // 阈值
        date: [new Date(2000, 10, 10, 10, 10), new Date(2035, 10, 11, 10, 10)]
      },
      total: 0,
      netCode: [], // 台网码数组,用于sheet命名
      loading: false,
      netCodeOptions: [],
      chanNumOptions: [],
      chanCodeOptions: []
    }
  },
  created () {
    this.getDriftData()
    this.getBaseData()
    this.getNetCode()
  },
  methods: {
    timestampToTime (date) {
      var Y = date.getFullYear() + '-'
      var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'
      var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' '
      var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':'
      var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':'
      var s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
      return Y + M + D + h + m + s
    },
    async getDriftData () {
      console.log('还没写')
    },
    async getBaseData () {
      const { data: { data: data1 } } = await getAllNetCode()
      this.netCodeOptions = data1.map(item => ({ value: item, label: item }))
      const { data: { data: data2 } } = await getAllChanNum()
      this.chanNumOptions = data2.map(item => ({ value: item, label: item }))
      const { data: { data: data3 } } = await getAllChanCode()
      this.chanCodeOptions = data3.map(item => ({ value: item, label: item }))
      // console.log(this.netCodeOptions, this.chanNumOptions, this.chanCodeOptions)
    },
    async getNetCode () {
      const { data: { data } } = await getNetCode()
      this.netCode = data
    },
    handleSizeChange (newSize) {
      this.pageInfo.pageSize = newSize
      this.getDriftData()
    },
    handleCurrentChange (newNum) {
      this.pageInfo.pageNum = newNum
      this.getDriftData()
    },
    queryData () {
      this.getDriftData()
    },
    clearFn () {
      this.selectChanCode = ''
      this.selectChanNum = ''
      this.selectNetCode = ''
      this.doubleThreshold = 0
      this.date = ''
      this.pageInfo = {
        endDate: '',
        pageNum: 1,
        pageSize: 10,
        startDate: ''
      }
      this.getDriftData()
    },
    exportExcel () {

    },
    // 表格颜色
    cellStyle ({ row, column, rowIndex }) {
      if (column.label === 'sumDcQty' && row.statusColorEnum === '绿色') {
        return 'background:#00FF7F;color:black;padding:0px'
      } else if (column.label === 'sumDcQty' && row.statusColorEnum === '黄色') {
        return 'background:yellow;color:black;padding:0px'
      } else if (column.label === 'sumDcQty' && row.statusColorEnum === '红色') {
        return 'background:red;color:black;padding:0px'
      }
      return 'padding:0px'
    }
  }
}
</script>
<style lang="css" scoped>
.page {
  margin-top: 20px;
}
</style>
